package com.zrwl.poscloud.base.utils;

import java.security.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class test {
    public static void main(String[] args) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd ");//注意后面有一个空格
        Calendar calStart = Calendar.getInstance();
        Calendar calEnd = Calendar.getInstance();
        calStart.set(Calendar.DAY_OF_MONTH, 1);
        calEnd.set(Calendar.DAY_OF_MONTH, calEnd.getActualMaximum(Calendar.DAY_OF_MONTH));
        System.out.println("月初:"+format.format(calStart.getTime()) + "00:00:00");
        System.out.println("月末:"+format.format(calEnd.getTime()) + "23:59:59");
        format = new SimpleDateFormat("yyyy-MM-dd ");//注意后面有一个空格
        calStart = Calendar.getInstance();
        calEnd = Calendar.getInstance();
        calStart.add(Calendar.MONTH, -1);//上一月
        calEnd.add(Calendar.MONTH, -1);
        calStart.set(Calendar.DAY_OF_MONTH, 1);
        calEnd.set(Calendar.DAY_OF_MONTH, calEnd.getActualMaximum(Calendar.DAY_OF_MONTH));
        System.out.println("上月开始时间:"+format.format(calStart.getTime()) + "00:00:00");
        System.out.println("上月结束时间:"+format.format(calEnd.getTime()) + "23:59:59");
    }
}
